<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<body>

<th:block th:fragment="plugin-modal">
    <el-dialog title="添加插件" :visible.sync="plugin_form.visible" center width="1100px" class="modern-plugin-dialog">
        <div class="plugin-modal-container">
            <!-- 顶部搜索区域 -->
            <div class="search-section">
                <div class="search-wrapper">
                <el-input
                    v-model="pluginSearchText"
                        placeholder="搜索插件名称、描述或分类..."
                    prefix-icon="el-icon-search"
                    clearable
                        size="large"
                        class="modern-search-input">
                </el-input>
                </div>
                <div class="search-stats">
                    <span class="stats-text">共找到 {{filteredPluginList.length}} 个插件</span>
                </div>
            </div>

            <!-- 选项卡区域 -->
            <div class="tabs-section">
                <el-tabs v-model="activeTab" class="modern-tabs" type="card">
                    <el-tab-pane class="tab-content" label="全部插件" name="all">
                        <div class="plugin-grid-container">
                    <div class="plugin-grid">
                                <div class="modern-plugin-card" 
                                     v-for="(item,index) in filteredPluginList" 
                                     :key="index" 
                                     :class="['plugin-type-' + item.pluginType, item.isBound ? 'is-bound' : '']">
                                    
                                    <!-- 卡片头部 -->
                                    <div class="card-header">
                                        <div class="plugin-icon-wrapper">
                                            <div class="plugin-icon" :class="'icon-type-' + item.pluginType">
                                    <i :class="getPluginIcon(item.pluginType)"></i>
                                </div>
                                            <div class="plugin-status-indicator" v-if="item.isBound">
                                                <i class="el-icon-check"></i>
                                            </div>
                                        </div>
                                        <div class="card-actions">
                                            <el-button 
                                                :type="item.isBound ? 'success' : 'primary'" 
                                                size="small" 
                                                circle 
                                                @click="selectPlugin(item)" 
                                                :disabled="item.isBound"
                                                class="action-btn">
                                        <i :class="item.isBound ? 'el-icon-check' : 'el-icon-plus'"></i>
                                    </el-button>
                                </div>
                            </div>
                                    
                                    <!-- 卡片内容 -->
                                    <div class="card-content">
                                        <h3 class="plugin-title">{{item.pluginLabel || item.pluginName}}</h3>
                                        <p class="plugin-description">{{item.pluginDesc || '暂无描述'}}</p>
                                        
                                        <!-- 标签区域 -->
                                        <div class="plugin-tags">
                                            <el-tag 
                                                size="mini" 
                                                :type="getPluginTypeTagType(item.pluginType)" 
                                                class="type-tag">
                                        {{item.pluginTypeName}}
                                    </el-tag>
                                            <span class="version-tag">v{{item.pluginVersion || '1.0.0'}}</span>
                                        </div>
                                        
                                        <!-- 底部信息 -->
                                        <div class="card-footer">
                                            <span class="category-info">
                                                <i class="el-icon-folder-opened"></i>
                                                {{item.pluginCategoryName || '通用工具'}}
                                            </span>
                                            <span class="bind-status" v-if="item.isBound">
                                                <i class="el-icon-success"></i>
                                                已添加
                                            </span>
                                        </div>
                                    </div>
                            </div>
                        </div>
                        
                        <!-- 空状态 -->
                            <div class="modern-empty-state" v-if="filteredPluginList.length === 0">
                                <div class="empty-icon">
                            <i class="el-icon-box"></i>
                                </div>
                                <h3 class="empty-title">暂无匹配的插件</h3>
                                <p class="empty-desc">尝试调整搜索条件或浏览其他分类</p>
                            </div>
                    </div>
                </el-tab-pane>
                
                    <el-tab-pane class="tab-content" label="MCP插件" name="mcp">
                        <div class="plugin-grid-container">
                    <div class="plugin-grid">
                                <div class="modern-plugin-card" 
                                     v-for="(item,index) in getPluginsByType(2)" 
                                     :key="'mcp-' + index" 
                                     :class="['plugin-type-' + item.pluginType, item.isBound ? 'is-bound' : '']">
                                    
                                    <div class="card-header">
                                        <div class="plugin-icon-wrapper">
                                            <div class="plugin-icon" :class="'icon-type-' + item.pluginType">
                                    <i :class="getPluginIcon(item.pluginType)"></i>
                                </div>
                                            <div class="plugin-status-indicator" v-if="item.isBound">
                                                <i class="el-icon-check"></i>
                                            </div>
                                        </div>
                                        <div class="card-actions">
                                            <el-button 
                                                :type="item.isBound ? 'success' : 'primary'" 
                                                size="small" 
                                                circle 
                                                @click="selectPlugin(item)" 
                                                :disabled="item.isBound"
                                                class="action-btn">
                                        <i :class="item.isBound ? 'el-icon-check' : 'el-icon-plus'"></i>
                                    </el-button>
                                </div>
                            </div>
                                    
                                    <div class="card-content">
                                        <h3 class="plugin-title">{{item.pluginLabel || item.pluginName}}</h3>
                                        <p class="plugin-description">{{item.pluginDesc || '暂无描述'}}</p>
                                        
                                        <div class="plugin-tags">
                                            <el-tag size="mini" :type="getPluginTypeTagType(item.pluginType)" class="type-tag">
                                        {{item.pluginTypeName}}
                                    </el-tag>
                                            <span class="version-tag">v{{item.pluginVersion || '1.0.0'}}</span>
                                        </div>
                                        
                                        <div class="card-footer">
                                            <span class="category-info">
                                                <i class="el-icon-folder-opened"></i>
                                                {{item.pluginCategoryName || '通用工具'}}
                                            </span>
                                            <span class="bind-status" v-if="item.isBound">
                                                <i class="el-icon-success"></i>
                                                已添加
                                            </span>
                                        </div>
                                    </div>
                            </div>
                        </div>
                        
                            <div class="modern-empty-state" v-if="getPluginsByType(2).length === 0">
                                <div class="empty-icon">
                            <i class="el-icon-cpu"></i>
                                </div>
                                <h3 class="empty-title">暂无MCP插件</h3>
                                <p class="empty-desc">MCP插件正在开发中，敬请期待</p>
                            </div>
                    </div>
                </el-tab-pane>
                
                    <el-tab-pane class="tab-content" label="内置插件" name="builtin">
                        <div class="plugin-grid-container">
                    <div class="plugin-grid">
                                <div class="modern-plugin-card" 
                                     v-for="(item,index) in getPluginsByType(3)" 
                                     :key="'builtin-' + index" 
                                     :class="['plugin-type-' + item.pluginType, item.isBound ? 'is-bound' : '']">
                                    
                                    <div class="card-header">
                                        <div class="plugin-icon-wrapper">
                                            <div class="plugin-icon" :class="'icon-type-' + item.pluginType">
                                    <i :class="getPluginIcon(item.pluginType)"></i>
                                </div>
                                            <div class="plugin-status-indicator" v-if="item.isBound">
                                                <i class="el-icon-check"></i>
                                            </div>
                                        </div>
                                        <div class="card-actions">
                                            <el-button 
                                                :type="item.isBound ? 'success' : 'primary'" 
                                                size="small" 
                                                circle 
                                                @click="selectPlugin(item)" 
                                                :disabled="item.isBound"
                                                class="action-btn">
                                        <i :class="item.isBound ? 'el-icon-check' : 'el-icon-plus'"></i>
                                    </el-button>
                                </div>
                            </div>
                                    
                                    <div class="card-content">
                                        <h3 class="plugin-title">{{item.pluginLabel || item.pluginName}}</h3>
                                        <p class="plugin-description">{{item.pluginDesc || '暂无描述'}}</p>
                                        
                                        <div class="plugin-tags">
                                            <el-tag size="mini" :type="getPluginTypeTagType(item.pluginType)" class="type-tag">
                                        {{item.pluginTypeName}}
                                    </el-tag>
                                            <span class="version-tag">v{{item.pluginVersion || '1.0.0'}}</span>
                                        </div>
                                        
                                        <div class="card-footer">
                                            <span class="category-info">
                                                <i class="el-icon-folder-opened"></i>
                                                {{item.pluginCategoryName || '通用工具'}}
                                            </span>
                                            <span class="bind-status" v-if="item.isBound">
                                                <i class="el-icon-success"></i>
                                                已添加
                                            </span>
                                        </div>
                                    </div>
                            </div>
                        </div>
                        
                            <div class="modern-empty-state" v-if="getPluginsByType(3).length === 0">
                                <div class="empty-icon">
                            <i class="el-icon-setting"></i>
                                </div>
                                <h3 class="empty-title">暂无内置插件</h3>
                                <p class="empty-desc">内置插件正在开发中，敬请期待</p>
                            </div>
                    </div>
                </el-tab-pane>
            </el-tabs>
            </div>
        </div>

        <!-- 底部操作区域 -->
        <div slot="footer" class="modern-dialog-footer">
            <div class="footer-info">
                <i class="el-icon-info"></i>
                <span>选择插件后将自动添加到智能体</span>
            </div>
            <div class="footer-actions">
                <el-button @click="plugin_form.visible = false" size="medium" class="cancel-btn">
                    <i class="el-icon-close"></i>
                    取消
                </el-button>
                <el-button type="primary" @click="handleConfirmAddPlugin" size="medium" class="confirm-btn">
                <i class="el-icon-check"></i>
                    完成
            </el-button>
            </div>
        </div>
    </el-dialog>
</th:block>

<style>
/* ==================== 现代化插件对话框样式 ==================== */

.modern-plugin-dialog .el-dialog {
    border-radius: 20px;
        overflow: hidden;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
}

.modern-plugin-dialog .el-dialog__header {
    background: transparent;
    color: white;
    padding: 25px 35px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
}

.modern-plugin-dialog .el-dialog__title {
        color: white;
    font-size: 22px;
    font-weight: 700;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.modern-plugin-dialog .el-dialog__headerbtn {
    top: 25px;
    right: 25px;
}

.modern-plugin-dialog .el-dialog__close {
        color: white;
    font-size: 20px;
    opacity: 0.8;
    transition: all 0.3s ease;
}

.modern-plugin-dialog .el-dialog__close:hover {
    opacity: 1;
    transform: scale(1.1);
}

.modern-plugin-dialog .el-dialog__body {
    padding: 0;
    background: #f8fafc;
    max-height: 75vh;
        overflow: hidden;
}

/* ==================== 插件模态框容器 ==================== */

.plugin-modal-container {
        display: flex;
        flex-direction: column;
    height: 100%;
    min-height: 600px;
}

/* ==================== 搜索区域 ==================== */

.search-section {
    padding: 25px 35px 20px;
    background: white;
    border-bottom: 1px solid #e2e8f0;
}

.search-wrapper {
    margin-bottom: 12px;
}

.modern-search-input .el-input__inner {
    border-radius: 50px;
    height: 48px;
    background: #f7fafc;
    border: 2px solid #e2e8f0;
    font-size: 15px;
    padding-left: 50px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}

.modern-search-input .el-input__inner:focus {
    border-color: #667eea;
        background: white;
    box-shadow: 0 4px 20px rgba(102, 126, 234, 0.15);
}

.modern-search-input .el-input__prefix {
    left: 18px;
    color: #a0aec0;
}

.search-stats {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.stats-text {
    color: #718096;
    font-size: 14px;
    font-weight: 500;
}

/* ==================== 选项卡区域 ==================== */

.tabs-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modern-tabs {
        flex: 1;
        display: flex;
        flex-direction: column;
        overflow: hidden;
    }

.modern-tabs .el-tabs__header {
        margin: 0;
    background: white;
    padding: 0 35px;
    border-bottom: 1px solid #e2e8f0;
}

.modern-tabs .el-tabs__nav-wrap {
    padding: 15px 0 0;
}

.modern-tabs .el-tabs__item {
    height: 45px;
    line-height: 45px;
    padding: 0 25px;
    font-weight: 600;
    font-size: 15px;
    border-radius: 12px 12px 0 0;
    margin-right: 8px;
    transition: all 0.3s ease;
    color: #718096;
    border: 2px solid transparent;
}

.modern-tabs .el-tabs__item:hover {
    color: #667eea;
    background: #f7fafc;
}

.modern-tabs .el-tabs__item.is-active {
    color: #667eea;
    background: #f7fafc;
    border-color: #e2e8f0;
    border-bottom-color: #f7fafc;
}

.modern-tabs .el-tabs__active-bar {
    display: none;
}

.modern-tabs .el-tabs__content {
        flex: 1;
        overflow-y: auto;
    padding: 0;
}

.tab-content {
    height: 100%;
}

/* ==================== 插件网格容器 ==================== */

.plugin-grid-container {
    padding: 25px 35px;
    height: 100%;
    overflow-y: auto;
    }

    .plugin-grid {
        display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 24px;
    padding-bottom: 20px;
}

/* ==================== 现代化插件卡片 ==================== */

.modern-plugin-card {
        background: white;
    border-radius: 16px;
        overflow: hidden;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    border: 2px solid #e2e8f0;
    position: relative;
    cursor: pointer;
}

.modern-plugin-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #667eea 0%, #764ba2 100%);
    transform: scaleX(0);
    transition: transform 0.3s ease;
}

.modern-plugin-card:hover {
    transform: translateY(-8px);
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
        border-color: #667eea;
    }

.modern-plugin-card:hover::before {
    transform: scaleX(1);
}

.modern-plugin-card.is-bound {
    border-color: #48bb78;
    background: linear-gradient(135deg, #f0fff4 0%, #c6f6d5 100%);
}

.modern-plugin-card.is-bound::before {
    background: linear-gradient(90deg, #48bb78 0%, #38a169 100%);
    transform: scaleX(1);
}

/* 卡片头部 */
.card-header {
        display: flex;
        justify-content: space-between;
        align-items: center;
    padding: 20px 24px 16px;
    background: linear-gradient(135deg, #f8fafc 0%, #edf2f7 100%);
}

.plugin-icon-wrapper {
    position: relative;
    }

    .plugin-icon {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    font-size: 20px;
        background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    transition: all 0.3s ease;
}

.modern-plugin-card:hover .plugin-icon {
    transform: scale(1.1);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

/* 插件类型图标样式 */
.icon-type-2 {
    background: linear-gradient(135deg, #4299e1 0%, #3182ce 100%) !important;
    box-shadow: 0 4px 12px rgba(66, 153, 225, 0.3) !important;
}

.icon-type-3 {
    background: linear-gradient(135deg, #ed8936 0%, #dd6b20 100%) !important;
    box-shadow: 0 4px 12px rgba(237, 137, 54, 0.3) !important;
}

.plugin-status-indicator {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    background: #48bb78;
    border-radius: 50%;
        display: flex;
        align-items: center;
        justify-content: center;
        color: white;
    font-size: 10px;
    border: 2px solid white;
    box-shadow: 0 2px 8px rgba(72, 187, 120, 0.3);
}

.card-actions {
    display: flex;
    gap: 8px;
}

.action-btn {
    width: 36px;
    height: 36px;
    border-radius: 12px;
    transition: all 0.3s ease;
    font-size: 16px;
}

.action-btn:not(:disabled):hover {
    transform: scale(1.1);
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.action-btn:disabled {
    background: #48bb78 !important;
    border-color: #48bb78 !important;
    cursor: not-allowed;
}

/* 卡片内容 */
.card-content {
    padding: 16px 24px 24px;
}

.plugin-title {
    margin: 0 0 12px 0;
    font-size: 18px;
    font-weight: 700;
        color: #2d3748;
        line-height: 1.4;
    display: -webkit-box;
    -webkit-line-clamp: 1;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.plugin-description {
    margin: 0 0 16px 0;
    font-size: 14px;
        color: #718096;
    line-height: 1.6;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    min-height: 44px;
}

.plugin-tags {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.type-tag {
    font-weight: 600;
    border-radius: 8px;
    padding: 4px 12px;
}

.version-tag {
    background: #e2e8f0;
    color: #4a5568;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.card-footer {
        display: flex;
        justify-content: space-between;
        align-items: center;
    padding-top: 12px;
    border-top: 1px solid #e2e8f0;
}

.category-info {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #718096;
    font-size: 13px;
        font-weight: 500;
    }

.bind-status {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #48bb78;
    font-size: 13px;
    font-weight: 600;
}

/* ==================== 空状态 ==================== */

.modern-empty-state {
        grid-column: 1 / -1;
        text-align: center;
    padding: 80px 20px;
        color: #a0aec0;
    }

.empty-icon {
    margin-bottom: 24px;
}

.empty-icon i {
    font-size: 64px;
    color: #cbd5e0;
}

.empty-title {
    margin: 0 0 12px 0;
    font-size: 20px;
    font-weight: 600;
    color: #4a5568;
}

.empty-desc {
    margin: 0;
    font-size: 15px;
    color: #718096;
}

/* ==================== 底部操作区域 ==================== */

.modern-dialog-footer {
    padding: 20px 35px;
    background: white;
    border-top: 1px solid #e2e8f0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.footer-info {
    display: flex;
    align-items: center;
    gap: 8px;
    color: #718096;
    font-size: 14px;
    font-weight: 500;
}

.footer-actions {
        display: flex;
        gap: 12px;
    }

.cancel-btn,
.confirm-btn {
    padding: 12px 24px;
    border-radius: 12px;
    font-weight: 600;
    font-size: 15px;
    transition: all 0.3s ease;
}

.cancel-btn {
    background: #f7fafc;
    border-color: #e2e8f0;
    color: #4a5568;
}

.cancel-btn:hover {
    background: #edf2f7;
    border-color: #cbd5e0;
    transform: translateY(-1px);
}

.confirm-btn {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    border: none;
    color: white;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.confirm-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(102, 126, 234, 0.4);
}

/* ==================== 响应式设计 ==================== */

@media (max-width: 768px) {
    .modern-plugin-dialog .el-dialog {
        width: 95% !important;
        margin: 20px auto !important;
    }
    
    .plugin-grid {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .search-section,
    .plugin-grid-container,
    .modern-dialog-footer {
        padding-left: 20px;
        padding-right: 20px;
    }
    
    .modern-tabs .el-tabs__header {
        padding: 0 20px;
    }
}

/* ==================== 动画效果 ==================== */

@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modern-plugin-card {
    animation: fadeInUp 0.6s ease forwards;
}

.modern-plugin-card:nth-child(1) { animation-delay: 0.1s; }
.modern-plugin-card:nth-child(2) { animation-delay: 0.2s; }
.modern-plugin-card:nth-child(3) { animation-delay: 0.3s; }
.modern-plugin-card:nth-child(4) { animation-delay: 0.4s; }
.modern-plugin-card:nth-child(5) { animation-delay: 0.5s; }
.modern-plugin-card:nth-child(6) { animation-delay: 0.6s; }

/* ==================== 滚动条样式 ==================== */

.plugin-grid-container::-webkit-scrollbar,
.modern-tabs .el-tabs__content::-webkit-scrollbar {
    width: 8px;
}

.plugin-grid-container::-webkit-scrollbar-track,
.modern-tabs .el-tabs__content::-webkit-scrollbar-track {
    background: #f1f5f9;
    border-radius: 4px;
}

.plugin-grid-container::-webkit-scrollbar-thumb,
.modern-tabs .el-tabs__content::-webkit-scrollbar-thumb {
    background: #cbd5e0;
    border-radius: 4px;
    transition: background 0.3s ease;
}

.plugin-grid-container::-webkit-scrollbar-thumb:hover,
.modern-tabs .el-tabs__content::-webkit-scrollbar-thumb:hover {
    background: #a0aec0;
}

</style>

</body>
</html>